package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/stj")
public class ServletToJsp extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		
//		response.setCharacterEncoding("utf-8");
//		response.setContentType("text/plain");
		
//		response.setContentType("text/html; charset=utf-8");
//		PrintWriter pw = response.getWriter();
//		pw.println("<h1>Servlet欢迎你~</h1>");
//		pw.println("<p>request.getContextPath()="+request.getContextPath()+"</p>");
		
		request.setAttribute("name", "张三");
		request.setAttribute("age", "20");
		HttpSession session = request.getSession();
		session.setAttribute("name", "李四");
		ServletContext application = request.getServletContext();
		application.setAttribute("name", "王五");
		request.getRequestDispatcher("/v2/j2.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
